package com.剑指offer.no04;

public class Soulution {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        if (matrix == null || matrix.length == 0) {
            return false;
        }

        if (matrix.length == 1 && matrix[0].length == 0) {
            return false;
        }

        int x = 0;    // 行
        int y = matrix[0].length - 1;   // 列

        while (x <= matrix.length - 1 && y >= 0) {
            int value = matrix[x][y];
            if (value == target)
                return true;
            if (value > target)
                y--;
            if (value < target)
                x++;
        }

        return false;
    }
}
